<?php


namespace App\Models\Marketing;


use App\Models\BaseModel;
use App\Models\Traits\KfSoftDeletes;
use App\Models\Traits\KfUid;
use Illuminate\Database\Eloquent\Relations\HasOne;

class ShopAdvertisementResourcesModel extends BaseModel
{
    use KfUid;
    use KfSoftDeletes;

    protected $table = 'marketing_shop_advertisement_resources';


    const RESOURCE_PLATFORM_ANDROID = 1;
    const RESOURCE_PLATFORM_IOS     = 2;

    const RESOURCE_PLATFORM_MAP = [
        self::RESOURCE_PLATFORM_ANDROID => '安卓',
        self::RESOURCE_PLATFORM_IOS     => 'iOS',
    ];

    const RESOURCE_TYPE_IMAGE = 1;
    const RESOURCE_TYPE_VIDEO = 2;
    const RESOURCE_TYPE_GIF   = 3;

    const RESOURCE_TYPE_MAP = [
        self::RESOURCE_TYPE_IMAGE => '图片',
        self::RESOURCE_TYPE_VIDEO => '视频',
        self::RESOURCE_TYPE_GIF   => 'gif'
    ];

    const SUPPORT_MIMETYPE_IMAGE = [
        'image/gif',
        'image/jpeg',
        'image/png',
        'image/webp',
    ];
    const SUPPORT_MIMETYPE_VIDEO = [
        'video/mp4',
        'video/mpeg',
        'video/avi',
        'video/quicktime'
    ];

    const IMAGE_IOS_WIDTH = 750;
    const IMAGE_IOS_HEIGHT = 1624;

    const IMAGE_ANDROID_WIDTH = 1080;
    const IMAGE_ANDROID_HEIGHT = 2146;

    public static function supportMineType():array
    {
        return array_merge(self::SUPPORT_MIMETYPE_IMAGE,self::SUPPORT_MIMETYPE_VIDEO);
    }

    public static function isImage($type):bool
    {
        return in_array($type,[self::RESOURCE_TYPE_IMAGE,self::RESOURCE_TYPE_GIF]);
    }

    public function advRel():HasOne
    {
        return $this->hasOne(ShopAdvertisementModel::class,'id','advId');
    }

}